Avoid over-reserving Vecs in compression codecs - #10483
Conversation
|
run benchmark compression |
This comment was marked as duplicate.
This comment was marked as duplicate.
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: CPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
| if to_flush == 0 { | ||
| break; | ||
| } | ||
| output_buf.reserve_exact(to_flush); |
There was a problem hiding this comment.
Emmm calling reserve_exact in a loop is a bit weird, does this guranteed calling once?
There was a problem hiding this comment.
It's not ideal but that's what the Zstd API looks like. end_stream will essentially always produce N followed by 0 bytes. Only multi-threaded encode would need multiple flushes as workers drain.
Just reserve works but I tried to avoid need for future shrinks.
From testing, this is often the first and last alloc too (output_buf Vecs don't seem to be reused much).
|
Did a (hopefully final) set of changes that should make both benches and memory usage happy. |
Which issue does this PR close?
This is a continuation to PR #10345.
Rationale for this change
The Vecs that we over-reserved can be long-lived, see issue above.
What changes are included in this PR?
Use zstd_safe contexts directly to compress/decompress, allowing us to append to Vec without reserving excessive amounts.
Remove redundant loops in
LZ4Codec.Are these changes tested?
Should be covered by existing tests.
One thing I felt while looking was the lack of tests regarding compression frames (some codecs look like they may decompress too much or not enough). Could add tests for that if desired.
Are there any user-facing changes?
No.